package com.example.admin.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.admin.entity.SysDictInfo;
import com.example.admin.entity.SysDictType;
import com.example.admin.mapper.SysDictTypeMapper;
import com.example.admin.service.ISysDictInfoService;
import com.example.admin.service.ISysDictTypeService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wangkai
 * @since 2019-06-04
 */
@Service("sysDictTypeService")
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService {

	@Resource(name = "sysDictInfoService")
	private ISysDictInfoService infoService;

	@Override
	@Transactional(readOnly = false, rollbackFor = { Exception.class, RuntimeException.class })
	public boolean deleteType(SysDictType type) {
		QueryWrapper<SysDictInfo> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("type_id", type.getId());
		if (infoService.remove(queryWrapper)) {
			if (!type.deleteById()) {
				throw new RuntimeException();
			}
		} else {
			throw new RuntimeException();
		}
		return true;
	}

}
